﻿Imports Microsoft.SharePoint
Imports Bussines.logic
Imports System.Data
Partial Class AcuerdosSistemaPoderosa
    Inherits System.Web.UI.Page
    Dim Util As New utiles
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim variosBL As New variosBL
        Dim _Procedure As String = Util.retornarParametros("SPacuerdosPoderosa")
        ViewState("columGrid") = Util.retornarParametros("CampoAcuerdoPoderosa")
        Dim _Campos() As String = ViewState("columGrid").ToString.Split(";")
        Dim Site As SPSite = New SPSite(ConfigurationManager.AppSettings("siteACTAS"))
        Dim web As SPWeb = Site.OpenWeb()
        Dim _user As String = Util.SepararCuentaActiveDirectory(web.CurrentUser.LoginName.ToString())
        _Procedure = _Procedure.Replace("[%usuario%]", _user)
        _Procedure = _Procedure.Replace("--", "").Replace("exec", "").Replace("drop", "").Replace("insert", "")

        'Dim dt As New DataTable

        'dt = variosBL.ListadoPendientesPoderosa(_Procedure)
        'gvListaPendiente.DataSource = dt
        'gvListaPendiente.DataBind()
        'dt.Dispose()
        'web.Close()
        'Site.Close()
        'For x As Int32 = 0 To gvListaPendiente.Columns.Count - 1
        '    gvListaPendiente.Columns(x).Visible = False
        'Next
        'ViewState("columGrid") = _Campos
        'For Each item As String In _Campos
        '    Dim strCampo() As String = item.Split("(")
        '    Dim strCMP As String = ""
        '    Dim strDES As String = ""
        '    If strCampo.Length > 0 Then
        '        strCMP = strCampo(0)
        '        strDES = strCampo(1).Replace(")", "")
        '    End If
        '    For Each col As DataControlField In gvListaPendiente.Columns
        '        If col.HeaderText = strCMP.Trim Then
        '            col.Visible = True
        '            Exit For
        '        End If
        '    Next
        'Next

        Dim ACTABL As New actasBL
        gvListaPendiente.DataSource = ACTABL.listar_AcuerdosPoderosa(_user, web.CurrentUser.LoginName.ToString())
        gvListaPendiente.DataBind()
    End Sub

    Protected Sub gvListaPendiente_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvListaPendiente.RowCreated
        'If (e.Row.RowType = DataControlRowType.Header) Then
        '    Dim _Campos() As String = ViewState("columGrid").ToString.Split(";")
        '    For Each item As String In _Campos
        '        Try
        '            Dim strCampo() As String = item.Split("(")
        '            Dim strCMP As String = ""
        '            Dim strDES As String = ""
        '            If strCampo.Length > 0 Then
        '                strCMP = strCampo(0)
        '                strDES = strCampo(1).Replace(")", "")
        '            End If
        '            For y As Integer = 0 To e.Row.Cells.Count - 1
        '                If e.Row.Cells(y).Text = strCMP.Trim Then
        '                    e.Row.Cells(y).Text = strDES
        '                End If
        '            Next
        '        Catch ex As Exception

        '        End Try
        '    Next
        'End If
    End Sub

    Protected Sub gvListaPendiente_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvListaPendiente.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim ibEdit As New ImageButton
            Dim imKPI As New Image
            ibEdit = CType(e.Row.FindControl("ibEditar"), ImageButton)
            imKPI = CType(e.Row.FindControl("imgKPI"), Image)
            Dim strTipoSist As String = DataBinder.Eval(e.Row.DataItem, "Sistema").ToString
            Dim strKPI As String = DataBinder.Eval(e.Row.DataItem, "Estado").ToString

            If strKPI.Trim = "PENDIENTE" Then
                imKPI.ImageUrl = ConfigurationManager.AppSettings("KPI_A").ToString
            ElseIf strKPI.Trim = "ATRASADO" Then
                imKPI.ImageUrl = ConfigurationManager.AppSettings("KPI_R").ToString
            End If

            If strTipoSist <> "AC" Then
                ibEdit.Visible = False
            Else
                ibEdit.OnClientClick = "javascript:parent.location.href='" & ConfigurationManager.AppSettings("Editar_acuerdo") & "?ID=" & DataBinder.Eval(e.Row.DataItem, "idAcuerdoSharepoint").ToString & "';"
            End If
        End If
    End Sub
End Class
